﻿@model Models.Models.UserList
@using WebApp.Classes

@{
    ViewBag.Title = "User Management";
}

@Scripts.Render("~/scripts/jquery.validate.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.js")
@Scripts.Render("~/scripts/partialViewValidation.js")

@Scripts.Render("~/scripts/app/EditUserPartial.js")
@Scripts.Render("~/scripts/app/" + Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath)) + ".js")

    <fieldset>
        @Html.GetTitle("/Images/glyphicons/png/glyphicons_043_group.png", new string[] { HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString() + "/" + ViewBag.Title })

        <div class="alert alert-info">
            Please select an account to edit, delete or create a new one.
            <div style='float: right' id="divRevoked">            
                Hide Revoked:
                <input type="checkbox" id="hideRevoked" style = "vertical-align: middle" @Html.Raw(ViewBag.hideRevoked == true ? "checked" : "") />
            </div>
        </div>

        <table width="100%">
            <tbody>
                <tr>
                    <td width="65%" valign="top">

                        <div style="height: 440px; border-style: solid; border-width: 1px; border-color: #DDDDDD">
                        <table class="table table-striped">
                          <thead>
                            <tr>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "FirstName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">First Name</a>
                                </th>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "LastName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Last Name</a>
                                </th>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "UserEmail", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">User Email</a>                    
                                </th>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "RevokeStatus", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked</a>                                                                                
                                </th>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DateRevoked", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked at</a>                                                                                
                                </th>
                                <th>
                                    <a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DateLastLogin", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Last Login</a>                                                                                                    
                                </th>
                            </tr>
                          </thead>
                          <tbody>
                            @{
                                foreach (var user in Model.List)
                                {
                                    <tr>
                                        <td>
                                            @Ajax.ActionLink(user.FirstName, "EditViewUser", new { id = @user.UserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditUser" }, new { @class = "grid" })
                                        </td>
                                        <td>
                                            @Ajax.ActionLink(user.LastName, "EditViewUser", new { id = @user.UserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditUser" }, new { @class = "grid" })
                                        </td>
                                        <td>
                                            @Ajax.ActionLink(user.UserEmail, "EditViewUser", new { id = @user.UserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditUser" }, new { @class = "grid" })
                                        </td>
                                        <td>
                                            @(user.RevokeStatus ? Html.Raw("<i class=\"icon-check\"></i>") : Html.Raw(""))
                                        </td>
                                        <td>
                                            @Ajax.ActionLink((user.DateRevoked.HasValue ? user.DateRevoked.Value.ToString("MM/dd/yyyy") : " "), "EditViewUser", new { id = @user.UserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditUser" }, new { @class = "grid" })
                                        </td>
                                        <td>
                                            @Ajax.ActionLink((user.DateLastLogin.HasValue ? user.DateLastLogin.Value.ToString("MM/dd/yyyy") : " "), "EditViewUser", new { id = @user.UserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditUser" }, new { @class = "grid" })
                                        </td>
                                    </tr>
                                }
                            }
                                <tr>
                                    <td colspan="5">
                                        <div class="pagination" style="margin: 0">
                                            <ul>
                                                @{
                                                    if (Model.PageIndex > 1)
                                                    { 
                                                        <li><a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex - 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-left"></i></a></li>
                                                    }

                                                    for (var i = 1; i <= WebApp.Classes.Statics.GetPages(Model.ResultCount); i++)
                                                    {
                                                        if (i == Model.PageIndex)
                                                        {
                                                            <li class="active"><a href="#">@i</a></li>
                                                        }
                                                        else
                                                        {
                                                            <li><a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", i, Model.SortColumn, Model.SortDirection)">@i</a></li>
                                                        }
                                                    }

                                                    if (Model.PageIndex != WebApp.Classes.Statics.GetPages(Model.ResultCount) && Model.ResultCount != 0)
                                                    { 
                                                        <li><a href="@String.Format("UserManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex + 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-right"></i></a></li>
                                                    }                                    
                                                }
                                            </ul>
                                        </div>                        
                                    </td>
                                    <td colspan="2" style="text-align: right">
                                        <br />
                                        <h5>Records: @Model.ResultCount</h5>
                                    </td>
                                </tr>
                            </tbody>                          
                        </table>
                        </div>
                        <br />

                       @{
                            if (new WebApp.Classes.UserRights(ViewBag.Title).FullControl)
                            { 
                                <div class="btn-group">    
                                    @Ajax.ImageActionLink("<i class=\"icon-plus-sign icon-white\"></i> Create New", "CreateUser", "Account", null, new AjaxOptions() { UpdateTargetId = "divEditUser" }, new { @id = "createUser", @class = "btn btn-inverse" })
                                </div>    
                            }
                        }
                    </td>
                    <td width="50%" valign="top">
                        <div id="divEditUser">

                        </div>                          
                    </td>
                </tr>
            </tbody>
        </table>        

    </fieldset>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
